package com.wujilin.okra.adapter;

import static com.wujilin.okra.Okra.getLayoutInflater;
import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.wujilin.okra.R;
import com.wujilin.okra.database.ModelCursor;
import com.wujilin.okra.model.Model;

/**
 * The adapter for the list of key results.
 * 
 * @author Belin Wu
 *
 */
public class KeyResultListAdapter extends CursorAdapter {
	private ModelCursor cursor;
	
	public KeyResultListAdapter(Context context, ModelCursor cursor) {
		super(context, cursor, 0);
		this.cursor = cursor;
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		return getLayoutInflater(context).inflate(R.layout.list_item_key_result, parent, false);
	}

	@Override
	public void bindView(View view, Context context, Cursor c) {
		TextView contentText = (TextView) view.findViewById(R.id.key_result_content);
		TextView gradeText = (TextView) view.findViewById(R.id.grade);
		TextView timeText = (TextView) view.findViewById(R.id.key_result_time);
		
		Model keyResult = cursor.getModel();
		String content = keyResult.getString("content");
		String grade = keyResult.getString("grade");
		String time = keyResult.getString("time");
		
		contentText.setText(content);
		gradeText.setText(grade);
		timeText.setText(time);
	}
}
